/*
 * This file is part of Cadmium.
 * Copyright (C) 2007-2010 Xavier Clerc.
 *
 * Cadmium is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * Cadmium is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package fr.x9c.cadmium.primitives.cadmiummath;

import fr.x9c.cadmium.kernel.Block;
import fr.x9c.cadmium.kernel.CodeRunner;
import fr.x9c.cadmium.kernel.Custom;
import fr.x9c.cadmium.kernel.Fail;
import fr.x9c.cadmium.kernel.Primitive;
import fr.x9c.cadmium.kernel.PrimitiveProvider;
import fr.x9c.cadmium.kernel.Value;
import fr.x9c.cadmium.primitives.cadmium.Cadmium;

/**
 * This class provides the primitives related to the <tt>java.lang.Math</tt> class.
 *
 * @author <a href="mailto:cadmium@x9c.fr">Xavier Clerc</a>
 * @version 1.1
 * @since 1.1
 */
@PrimitiveProvider
public final class Floats {

    /**
     * No instance of this class.
     */
    private Floats() {
    } // end empty constructor

    /**
     * Returns the float value for <i>e</i>.
     * @param ctxt context
     * @param unit ignore
     * @return the float value for <i>e</i>
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_get_e(final CodeRunner ctxt,
                                                final Value unit)
        throws Fail.Exception {
        try {
            final Block res = Block.createDouble(Math.E);
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_get_e(CodeRunner, Value)'

    /**
     * Returns the float value for <i>pi</i>.
     * @param ctxt context
     * @param unit ignore
     * @return the float value for <i>pi</i>
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_get_pi(final CodeRunner ctxt,
                                                 final Value unit)
        throws Fail.Exception {
        try {
            final Block res = Block.createDouble(Math.PI);
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_get_pi(CodeRunner, Value)'

    /**
     * Returns the <i>abs</i> value of the passed value.
     * @param ctxt context
     * @param x float value
     * @return <i>abs(x)</i>
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_abs(final CodeRunner ctxt,
                                              final Value x)
        throws Fail.Exception {
        try {
            final Block res = Block.createDouble(Math.abs(x.asBlock().asDouble()));
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_abs(CodeRunner, Value)'

    /**
     * Returns the <i>acos</i> value of the passed value.
     * @param ctxt context
     * @param x float value
     * @return <i>acos(x)</i>
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_acos(final CodeRunner ctxt,
                                               final Value x)
        throws Fail.Exception {
        try {
            final Block res = Block.createDouble(Math.acos(x.asBlock().asDouble()));
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_acos(CodeRunner, Value)'

    /**
     * Returns the <i>asin</i> value of the passed value.
     * @param ctxt context
     * @param x float value
     * @return <i>asin(x)</i>
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_asin(final CodeRunner ctxt,
                                               final Value x)
        throws Fail.Exception {
        try {
            final Block res = Block.createDouble(Math.asin(x.asBlock().asDouble()));
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_asin(CodeRunner, Value)'

    /**
     * Returns the <i>atan</i> value of the passed value.
     * @param ctxt context
     * @param x float value
     * @return <i>atan(x)</i>
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_atan(final CodeRunner ctxt,
                                               final Value x)
        throws Fail.Exception {
        try {
            final Block res = Block.createDouble(Math.atan(x.asBlock().asDouble()));
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_atan(CodeRunner, Value)'

    /**
     * Returns the angle from the conversion of rectangular coordinates
     * <i>(x, y)</i> into polar coordinates.
     * @param ctxt context
     * @param x float value
     * @param y float value
     * @return the angle from the conversion of rectangular coordinates
     *         <i>(x, y)</i> into polar coordinates
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_atan2(final CodeRunner ctxt,
                                                final Value x,
                                                final Value y)
        throws Fail.Exception {
        try {
            final Block res = Block.createDouble(Math.atan2(x.asBlock().asDouble(),
                                                            y.asBlock().asDouble()));
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_atan2(CodeRunner, Value, Value)'

    /**
     * Returns the <i>cbrt</i> value (that is cube root) of the passed value.
     * @param ctxt context
     * @param x float value
     * @return <i>cbrt(x)</i>
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_cbrt(final CodeRunner ctxt,
                                               final Value x)
        throws Fail.Exception {
        try {
            final Block res = Block.createDouble(Math.cbrt(x.asBlock().asDouble()));
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_cbrt(CodeRunner, Value)'

    /**
     * Returns the smallest integer value that is greater than or equal to
     * the passed value.
     * @param ctxt context
     * @param x float value
     * @return the smallest integer value that is greater than or equal to <i>x</i>
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_ceil(final CodeRunner ctxt,
                                               final Value x)
        throws Fail.Exception {
        try {
            final Block res = Block.createDouble(Math.ceil(x.asBlock().asDouble()));
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_ceil(CodeRunner, Value)'

    /**
     * Returns the first argument, with the sign of the second one.
     * @param ctxt context
     * @param x float value
     * @param y float value
     * @return the <i>x</i> absolute value, with the sign of <i>y</i>
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_copy_sign(final CodeRunner ctxt,
                                                    final Value x,
                                                    final Value y)
        throws Fail.Exception {
        try {
            final Block res = Block.createDouble(Math.copySign(x.asBlock().asDouble(),
                                                               y.asBlock().asDouble()));
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_copy_sign(CodeRunner, Value, Value)'

    /**
     * Returns the <i>cos</i> value of the passed value.
     * @param ctxt context
     * @param x float value
     * @return <i>cos(x)</i>
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_cos(final CodeRunner ctxt,
                                              final Value x)
        throws Fail.Exception {
        try {
            final Block res = Block.createDouble(Math.cos(x.asBlock().asDouble()));
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_cos(CodeRunner, Value)'

    /**
     * Returns the <i>cosh</i> value of the passed value.
     * @param ctxt context
     * @param x float value
     * @return <i>cosh(x)</i>
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_cosh(final CodeRunner ctxt,
                                               final Value x)
        throws Fail.Exception {
        try {
            final Block res = Block.createDouble(Math.cosh(x.asBlock().asDouble()));
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_cosh(CodeRunner, Value)'

    /**
     * Returns the <i>exp</i> value of the passed value.
     * @param ctxt context
     * @param x float value
     * @return <i>exp(x)</i>
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_exp(final CodeRunner ctxt,
                                              final Value x)
        throws Fail.Exception {
        try {
            final Block res = Block.createDouble(Math.exp(x.asBlock().asDouble()));
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_exp(CodeRunner, Value)'

    /**
     * Returns the <i>exp</i> value of the passed value minus one.
     * @param ctxt context
     * @param x float value
     * @return <i>exp(x) - 1</i>
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_exp_m1(final CodeRunner ctxt,
                                                 final Value x)
        throws Fail.Exception {
        try {
            final Block res = Block.createDouble(Math.expm1(x.asBlock().asDouble()));
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_exp_m1(CodeRunner, Value)'

    /**
     * Returns the largest integer value that is less than or equal to the passed value.
     * @param ctxt context
     * @param x float value
     * @return the largest integer value that is less than or equal to <i>x</i>
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_floor(final CodeRunner ctxt,
                                                final Value x)
        throws Fail.Exception {
        try {
            final Block res = Block.createDouble(Math.floor(x.asBlock().asDouble()));
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_floor(CodeRunner, Value)'

    /**
     * Returns the unbiased exponent of the passed value.
     * @param ctxt context
     * @param x float value
     * @return the unbiased exponent of the passed value.
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_get_exponent(final CodeRunner ctxt,
                                                       final Value x)
        throws Fail.Exception {
        try {
            return Value.createFromLong(Math.getExponent(x.asBlock().asDouble()));
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_get_exponent(CodeRunner, Value)'

    /**
     * Returns <i>sqrt(x**2+y**2)</i>.
     * @param ctxt context
     * @param x float value
     * @param y float value
     * @return <i>sqrt(x**2+y**2)</i>
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_hypot(final CodeRunner ctxt,
                                                final Value x,
                                                final Value y)
        throws Fail.Exception {
        try {
            final Block res = Block.createDouble(Math.hypot(x.asBlock().asDouble(),
                                                            y.asBlock().asDouble()));
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_hypot(CodeRunner, Value, Value)'

    /**
     * Returns the remainder of <i>x / y</i>.
     * @param ctxt context
     * @param x float value
     * @param y float value
     * @return the remainder of <i>x / y</i>
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_ieee_remainder(final CodeRunner ctxt,
                                                         final Value x,
                                                         final Value y)
        throws Fail.Exception {
        try {
            final Block res = Block.createDouble(Math.IEEEremainder(x.asBlock().asDouble(),
                                                                    y.asBlock().asDouble()));
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_ieee_remainder(CodeRunner, Value, Value)'

    /**
     * Returns the base <i>e</i> logarithm of the passed value.
     * @param ctxt context
     * @param x float value
     * @return <i>log(x)</i>
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_log(final CodeRunner ctxt,
                                              final Value x)
        throws Fail.Exception {
        try {
            final Block res = Block.createDouble(Math.log(x.asBlock().asDouble()));
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_log(CodeRunner, Value)'

    /**
     * Returns the base 10 logarithm of the passed value.
     * @param ctxt context
     * @param x float value
     * @return <i>log10(x)</i>
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_log10(final CodeRunner ctxt,
                                                final Value x)
        throws Fail.Exception {
        try {
            final Block res = Block.createDouble(Math.log10(x.asBlock().asDouble()));
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_log10(CodeRunner, Value)'

    /**
     * Returns the base <i>e</i> logarithm of the passed value plus one.
     * @param ctxt context
     * @param x float value
     * @return <i>log(x) + 1</i>
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_log1p(final CodeRunner ctxt,
                                                final Value x)
        throws Fail.Exception {
        try {
            final Block res = Block.createDouble(Math.log1p(x.asBlock().asDouble()));
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_log1p(CodeRunner, Value)'

    /**
     * Returns the maximum of the passed value.
     * @param ctxt context
     * @param x float value
     * @param y float value
     * @return the maximum of <i>x</i> and <i>y</i>
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_max(final CodeRunner ctxt,
                                              final Value x,
                                              final Value y)
        throws Fail.Exception {
        try {
            final Block res = Block.createDouble(Math.max(x.asBlock().asDouble(),
                                                          y.asBlock().asDouble()));
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_max(CodeRunner, Value, Value)'

    /**
     * Returns the minimum of the passed value.
     * @param ctxt context
     * @param x float value
     * @param y float value
     * @return the minimum of <i>x</i> and <i>y</i>
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_min(final CodeRunner ctxt,
                                              final Value x,
                                              final Value y)
        throws Fail.Exception {
        try {
            final Block res = Block.createDouble(Math.min(x.asBlock().asDouble(),
                                                          y.asBlock().asDouble()));
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_min(CodeRunner, Value, Value)'

    /**
     * Returns the value adjacent to the first argument in the direction of the second one.
     * @param ctxt context
     * @param x float value
     * @param y float value
     * @return the value adjecent to <i>x</i> in the direction of <i>y</i>
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_next_after(final CodeRunner ctxt,
                                                     final Value x,
                                                     final Value y)
        throws Fail.Exception {
        try {
            final Block res = Block.createDouble(Math.nextAfter(x.asBlock().asDouble(),
                                                                y.asBlock().asDouble()));
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_next_after(CodeRunner, Value, Value)'

    /**
     * Returns the value adjacent to the first argument in the direction of positive infinity.
     * @param ctxt context
     * @param x float value
     * @return the value adjecent to <i>x</i> in the direction of positive infinity
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_next_up(final CodeRunner ctxt,
                                                  final Value x)
        throws Fail.Exception {
        try {
            final Block res = Block.createDouble(Math.nextUp(x.asBlock().asDouble()));
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_next_up(CodeRunner, Value)'

    /**
     * Returns the first passed value raised to the power of the second one.
     * @param ctxt context
     * @param x float value
     * @param y float value
     * @return <i>x**y</i>
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_pow(final CodeRunner ctxt,
                                              final Value x,
                                              final Value y)
        throws Fail.Exception {
        try {
            final Block res = Block.createDouble(Math.pow(x.asBlock().asDouble(),
                                                          y.asBlock().asDouble()));
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_pow(CodeRunner, Value, Value)'

    /**
     * Returns a random value between 0.0 (inclusive) and 1.0 (exclusive).
     * @param ctxt context
     * @param unit ignored
     * @return a random value between 0.0 (inclusive) and 1.0 (exclusive)
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_random(final CodeRunner ctxt,
                                                 final Value unit)
        throws Fail.Exception {
        try {
            final Block res = Block.createDouble(Math.random());
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_random(CodeRunner, Value)'

    /**
     * Returns the integer value closest to the passed value.
     * @param ctxt context
     * @param x float value
     * @return the integer value closest to <i>x</i>
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_rint(final CodeRunner ctxt,
                                               final Value x)
        throws Fail.Exception {
        try {
            final Block res = Block.createDouble(Math.rint(x.asBlock().asDouble()));
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_rint(CodeRunner, Value)'

    /**
     * Returns the integer value closest to the passed value.
     * @param ctxt context
     * @param x float value
     * @return the integer value closest to <i>x</i>
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_round(final CodeRunner ctxt,
                                                final Value x)
        throws Fail.Exception {
        try {
            final Block res = Block.createCustom(Custom.INT_64_SIZE,
                                                 Custom.INT_64_OPS);
            res.setInt64(Math.round(x.asBlock().asDouble()));
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_round(CodeRunner, Value)'

    /**
     * Returns the <i>x*2**y</i>.
     * @param ctxt context
     * @param x float value
     * @param y float value
     * @return <i>x*2**y</i>
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_scalb(final CodeRunner ctxt,
                                                final Value x,
                                                final Value y)
        throws Fail.Exception {
        try {
            final Block res = Block.createDouble(Math.scalb(x.asBlock().asDouble(),
                                                            y.asLong()));
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_scalb(CodeRunner, Value, Value)'

    /**
     * Returns a value incating the sign of the passed value.
     * @param ctxt context
     * @param x float value
     * @return 0.0 if the passed value is zero,
     *         1.0 if the passed value is greater than zero,
     *         -1.0 if the passed value is lower than zero
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_signum(final CodeRunner ctxt,
                                                 final Value x)
        throws Fail.Exception {
        try {
            final Block res = Block.createDouble(Math.signum(x.asBlock().asDouble()));
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_signum(CodeRunner, Value)'

    /**
     * Returns the <i>sin</i> value of the passed value.
     * @param ctxt context
     * @param x float value
     * @return <i>sin(x)</i>
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_sin(final CodeRunner ctxt,
                                              final Value x)
        throws Fail.Exception {
        try {
            final Block res = Block.createDouble(Math.sin(x.asBlock().asDouble()));
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_sin(CodeRunner, Value)'

    /**
     * Returns the <i>sinh</i> value of the passed value.
     * @param ctxt context
     * @param x float value
     * @return <i>sinh(x)</i>
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_sinh(final CodeRunner ctxt,
                                               final Value x)
        throws Fail.Exception {
        try {
            final Block res = Block.createDouble(Math.sinh(x.asBlock().asDouble()));
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_sinh(CodeRunner, Value)'

    /**
     * Returns the <i>sqrt</i> value (that is square root) of the passed value.
     * @param ctxt context
     * @param x float value
     * @return <i>sqrt(x)</i>
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_sqrt(final CodeRunner ctxt,
                                               final Value x)
        throws Fail.Exception {
        try {
            final Block res = Block.createDouble(Math.sqrt(x.asBlock().asDouble()));
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_sqrt(CodeRunner, Value)'

    /**
     * Returns the <i>tan</i> value of the passed value.
     * @param ctxt context
     * @param x float value
     * @return <i>tan(x)</i>
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_tan(final CodeRunner ctxt,
                                              final Value x)
        throws Fail.Exception {
        try {
            final Block res = Block.createDouble(Math.tan(x.asBlock().asDouble()));
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_tan(CodeRunner, Value)'

    /**
     * Returns the <i>tanh</i> value of the passed value.
     * @param ctxt context
     * @param x float value
     * @return <i>tanh(x)</i>
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_tanh(final CodeRunner ctxt,
                                               final Value x)
        throws Fail.Exception {
        try {
            final Block res = Block.createDouble(Math.tanh(x.asBlock().asDouble()));
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_tanh(CodeRunner, Value)'

    /**
     * Converts an angle measured in radians into an equivalent angle measured in degrees.
     * @param ctxt context
     * @param x float value
     * @return returns the value of the passed angle in degrees
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_to_degrees(final CodeRunner ctxt,
                                                     final Value x)
        throws Fail.Exception {
        try {
            final Block res = Block.createDouble(Math.toDegrees(x.asBlock().asDouble()));
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_to_degrees(CodeRunner, Value)'

    /**
     * Converts an angle measured in degrees into an equivalent angle measured in radians.
     * @param ctxt context
     * @param x float value
     * @return returns the value of the passed angle in radians
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_to_radians(final CodeRunner ctxt,
                                                     final Value x)
        throws Fail.Exception {
        try {
            final Block res = Block.createDouble(Math.toRadians(x.asBlock().asDouble()));
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_to_radians(CodeRunner, Value)'

    /**
     * Returns the size of an <i>ulp</i> for the passed value.
     * @param ctxt context
     * @param x float value
     * @return the size of an <i>ulp</i> for <i>x</i>
     * @throws Fail.Exception if any error occurs
     */
    @Primitive
    public static Value cadmiummath_float_ulp(final CodeRunner ctxt,
                                              final Value x)
        throws Fail.Exception {
        try {
            final Block res = Block.createDouble(Math.ulp(x.asBlock().asDouble()));
            return Value.createFromBlock(res);
        } catch (final Exception e) {
            Cadmium.fail(ctxt, e);
            return Value.UNIT; // never reached
        } // end try/catch
    } // end method 'cadmiummath_float_ulp(CodeRunner, Value)'

} // end class 'Floats'
